package t211201;

/**
 * @Author: DengJia
 * @Date: 2021/12/1 21:21
 * @Description: 协变返回类型
 */

public class CovariantReturn {
    public static void main(String[] args) {
        // ★ 在导出类中被覆盖方法可以返回基类方法的返回类型的某种导出类型

        Mill m = new Mill();
        Grain g = m.process();
        System.out.println(g);

        m = new WheatMill();
        g = m.process();
        System.out.println(g);
    }
}

class Grain {
    public String toString() {
        return "Grain";
    }
}

class Wheat extends Grain {
    @Override
    public String toString() {
        return "Wheat";
    }
}

class Mill {
    Grain process() {
        return new Grain();
    }
}

class WheatMill extends Mill {
    @Override
    Wheat process() {
        return new Wheat();
    }
}
